<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>24题寻找质数</title>
    <script>
        function getPerfectNumber() {
            let numArr = [];
            for (let i = 1000; i < 10000; i++) {
                let n = i.toString();
                let total = 0;
                for (let j = 0; j < n.length; j++) {
                    let subNum = parseInt(n[j]);
                    total += Math.pow(subNum, 4);
                }
                if (total === i) {
                    numArr.push(i);
                }
            }
            
            let p = document.getElementById('sum');
            p.innerHTML = '四位水仙花数：' + numArr.toString();
        }
    </script>
</head>
<body>
    <p>
        点击按钮查看四位水仙花数<input type="button" value="查看" onclick="getPerfectNumber()">
    </p>
    <p id="sum">四位水仙花数：</p>
</body>
</html>